﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.Services.Protocols;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;

namespace Barbar.MapReport.HtmlRender.Facade {
  /// <summary>
  /// Ladící rozšírení soap protokolu
  /// </summary>
  public class SoapDebuggingExtension : SoapExtension {
    /// <summary>
    /// Zpracování soap zprávy
    /// </summary>
    /// <param name="message"></param>
    public override void ProcessMessage(SoapMessage message) {
      if (message.Exception != null) {
        if (message.Stage == SoapMessageStage.AfterSerialize) {
          StringBuilder sb = new StringBuilder();
          Exception e = message.Exception;
          while (e != null) {
            sb.Append(e.Message);
            sb.Append(e.StackTrace);
            e = e.InnerException;
          }
          // TODO: log message
        }
      }
    }

    /// <summary>
    /// Zpracování soap inicializace
    /// </summary>
    /// <param name="initializer"></param>
    public override void Initialize(object initializer) {
    }


    /// <summary>
    /// When the SOAP extension is accessed for the first time, the XML Web
    /// service method it is applied to is accessed to store the file
    /// name passed in, using the corresponding SoapExtensionAttribute. 
    /// </summary>
    /// <param name="methodInfo"></param>
    /// <param name="attribute"></param>
    /// <returns></returns>
    public override object GetInitializer(LogicalMethodInfo methodInfo, SoapExtensionAttribute attribute) {
      return null;
    }

    /// <summary>
    /// The SOAP extension was configured to run using a configuration file
    /// instead of an attribute applied to a specific XML Web service
    /// method.
    /// </summary>
    /// <param name="serviceType"></param>
    /// <returns></returns>
    public override object GetInitializer(Type serviceType) {
      // Return a file name to log the trace information to, based on the
      // type.
      return null;
    }
  }
}
